package P106_DynamicProxy;

public class StaticProxy {
    //抽象主题角色
    interface Subject {
        public void request();
    }

    //具体主题角色
    class RealSubject implements Subject {

        @Override
        public void request() {
            System.out.println("什么都不做");
        }
    }

    class ProxySubject implements Subject {

        private Subject subject = null;

        //默认代理
        public ProxySubject() {
            subject = new RealSubject();
        }

        public ProxySubject(Subject subject) {
            this.subject = subject;
        }

        @Override
        public void request() {
            before();
            subject.request();
            after();
        }

        //预处理
        private void before() {
            System.out.println("预处理");
        }

        //后处理
        private void after() {
            System.out.println("后处理");
        }
    }
}
